﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Principal.aspx.cs" Inherits="EGuayas.Web.Principal" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>PLASA</title>
    <link rel="Shortcut Icon" href="favicon.ico" type="image/x-icon" />
    <!-- Load Ext JS --> 
    <script src="Resources/js/Global.js"></script>
    <script src="Resources/js/ExtNs.js"></script>
    <link  href="Resources/css/AlertaViewer.css"  rel="stylesheet" />
    <script type="text/javascript" >

        crearTab = function (path, id, rurl, text) {
            var tab;
            //Creacion del tab
            tab = App.tapPrincipal.add(new Ext.Panel({
                id: id,
                border: false,
                loader:
                {
                    loadMask:
                        {
                            showMask: true
                        },
                    renderer: "frame",
                    url: rurl
                },
                bodyPadding: 6,
                closable: true,
                title: text,
                /*
                tbar: [
                '->',
                {
                text: 'Recargar',
                iconCls: '#ArrowRefresh',
                handler: function () {
                            Ext.getCmp(id).reload(true);
                            }
                    }]*/
            }));
            App.tapPrincipal.setActiveTab(tab);
        }
        //Funcion para crear un nuevo tab o poner como activo al tab si no existe 
        cargarTab = function (path, href, id, text) {
            var tab = App.tapPrincipal.getComponent(id);

            if (tab) {
                App.tapPrincipal.setActiveTab(tab);
            } else {
                crearTab(path, id, href, text);
            }

        }
        clickItem = function (item, record, node, index, e)
        {
            cargarTab(record.data.hrefTarget, record.data.hrefTarget, record.data.id, record.data.text);
        }
        closeSessionUser = function () {
            App.direct.DeleteSession({
                success: function (result) {
                    document.location.href = AppGlobalJs.obtenerPath() + "/pgLogin.aspx";
                },
                eventMask: {
                    showMask: true,
                    minDelay: 500
                }
            });
        }
        updateMaskTask = function (msg) {

        };
       
       gridAlertaReload = function (estado) {
           var _grid = Ext.ComponentQuery.query("[cls=feed-detail]")[0].down("gridpanel");
           if (_grid) {
               _grid.getStore().reload();
           }
       
           var _panel = Ext.ComponentQuery.query("[cls=feed-info]")[0];
           if (_panel) {
               switch(estado)
               {
                   default:
                       _panel.setIcon("#EmailOpenImage");
                       break;
                   case "I":
                       _panel.setIcon("#EmailTransfer");
                       break;
                }
           }
        };
       activateTab = function (item, newTab) {
            //Actualiza datos de alertas cuando se activa tab notificaciones
            if (newTab.title == "Notificaciones") {
                gridAlertaReload('I');
            }
        };
        refreshTabActive = function (tab) {
            var pnl = tab.getActiveTab();
            var id = pnl.id;
            var tabNow=Ext.getCmp(id);
            if (tabNow!=null)
            tabNow.reload(true);
        };
       
    </script>
</head>
<body>
    <ext:ResourceManager  ID="ResourceManager1" runat="server"></ext:ResourceManager>    
    <ext:TaskManager ID="TaskManager1" runat="server">
            <Tasks>
                <ext:Task
                    TaskID="longaction"
                    Interval="600000"
                    AutoRun="false">                   
                    <DirectEvents>
                        <Update OnEvent="Refresh" />
                    </DirectEvents>                   
                </ext:Task>
            </Tasks>
    </ext:TaskManager>
     <ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout" >
        <Items>
            <ext:Window ID="w1" runat="server"
                    Width="300"
                    Height="190"
                    Resizable="false"
                    ButtonAlign="Center"
                    Hidden="true"
                    Constrain="true"
                    Layout="FitLayout">
                    <Items>
                        <ext:Panel ID="Panel1" runat="server" Border="false">
                            <Loader runat="server"  Url="Usuario/pgClave.aspx" Mode="Frame"></Loader>
                        </ext:Panel>
                    </Items>
            </ext:Window>
            <%--<ext:Panel ID="panCabecera" runat="server" Region="North" Height="100" BodyPadding="0" TitleCollapse="false" Html="Encabezado de aplicación"
                Split="true" Collapsible ="true" Header="false" />--%>
            <ext:Panel ID="panMenu" runat="server" Region="West" Layout="AccordionLayout" Width="225" MinWidth="225" MaxWidth="400" 
                Split="true" Collapsible="true" Header="false">
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" Cls="x-toolbar1" runat="server" AnchorWidth="100">
                        <Items>      
                            <ext:Image ID="Image1" runat="server" ImageUrl="Resources/images/interna_cabecera01.jpg" Height="100"></ext:Image>
                           
                        </Items>
                        </ext:Toolbar>
                </TopBar>
                <Items>
                    
                </Items>
            </ext:Panel>
            <ext:Panel ID="panCenter" runat="server" Region="Center" Layout="BorderLayout">
                <Items>                    
                     <ext:Container ID="Container1" runat="server" Layout="HBoxLayout" Height="30" Region="North">
                     <Items>
                         <ext:Toolbar runat="server" Flex="1">
                             <Items>
                                  <ext:Label runat="server" ID="lblUser" IconAlign="Left" Height="30"  Icon="UserEarth" ></ext:Label> 
                                  <ext:ToolbarFill ID="ToolbarFill1" runat="server" /> 
                                  <%--   
                                    <ext:Button ID="btnClave" runat="server" Flat="true" Icon="UserKey" ToolTip="Clave" Text="Clave" Width="55" Height="30">
                                        <Listeners>
                                            <Click Handler="App.w1.show();" />
                                        </Listeners>
                                    </ext:Button>  
                                    --%>          
                                    <ext:Button ID="btnLock" runat="server" Flat="true" Icon="LockOpen" ToolTip="Salir" Text="Salir" Width="55" Height="30">
                                        <Listeners>
                                            <Click Handler="closeSessionUser();" />
                                        </Listeners>
                                    </ext:Button>
                             </Items>
                         </ext:Toolbar>
                     
                     </Items>
                     </ext:Container> 
                    <ext:TabPanel ID="tapPrincipal" runat="server" Flex="1" Region="Center">
                        <TabBar> 
                             <ext:ToolbarFill ID="ToolbarFill2" runat="server" />
                            <ext:Button ID="Button1" runat="server"  Text="Recargar" Flat="true" Icon="ArrowRefresh">
                                <Listeners>
                                    <Click Handler="refreshTabActive(#{tapPrincipal});" />
                                </Listeners>
                            </ext:Button>                           
                         </TabBar>
                        <Items>
                              <ext:UserControlLoader ID="UserControlLoader1" runat="server" Path="Notificacion/AlertaInfo.ascx" OnComponentAdded="FeedInfoAdded" />
                        </Items>
                        <Listeners>
                             <TabChange Handler="activateTab(item,newTab);"></TabChange>
                        </Listeners>
                    </ext:TabPanel>
                </Items>
            </ext:Panel>
            
        </Items>
    </ext:Viewport>
</body>
</html>
